package com.frxuexi.document

import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.RequestType
import com.frxuexi.lib_base.entity.ApiResponse
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class DocViewModel @Inject constructor(private val docRepository: DocRepository):BaseViewModel<DocIntent>() {
    override fun handleIntent(intent: DocIntent) {
        when(intent){
            is DocIntent.getDocs->{
                httpRequest(docRepository.getDocs(intent.map) as Flow<ApiResponse<Any>>)
            }
            is DocIntent.deleteDoc->{
                httpRequest(docRepository.deleteDocs(hashMapOf("FileId" to intent.fileId)) as Flow<ApiResponse<Any>>,RequestType.DELETE)
            }
            is DocIntent.scanFile->{
                scanFile(intent.file)
            }
            is DocIntent.uploadFile->{
                httpRequest(docRepository.uploadDoc(intent.name,intent.path) as Flow<ApiResponse<Any>>,RequestType.UPLOAD)
            }
        }
    }
}